package com.example.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

import com.example.fw.ContactObject;
import com.example.fw.Contacts;

public class ContactCreationTests extends TestBase {

	@Test(dataProvider = "contactsFromFile", dataProviderClass = ContactDataGenerator.class)
//	@Test(dataProvider = "randomContacts")
	public void testValidContactCanBeCreated(ContactObject validContact, boolean valid) throws Exception {
			Contacts oldContactList = app.getHibernateHelper().getContacts();
			app.getContactHelper().createContact(validContact);
			Contacts newContactList = app.getHibernateHelper().getContacts();
			if (valid)	{
				assertThat(newContactList, equalTo(oldContactList.withAdded(validContact)));		//	hamcrest style lesson 4 65:00
			} else	{
				assertThat(newContactList, equalTo(oldContactList));
			}
	}

//	@AfterMethod		// lesson 7 ~ 75:00
//	public void testUiConformsWithDb()	{
//		if ((app.getProperty("ui.check") != null) && (app.getProperty("db.check") != null))	{
//			Contacts uiList = app.getContactHelper().getUiContacts();
//			Contacts dbList = app.getHibernateHelper().getContacts();
//			assertThat(uiList, equalTo(dbList));
//		}
//	}
}